Skip to content

Conversation

@pktharindu
Copy link
Contributor

Description

Fixes #32.

Problem

The ConverseTextHandler was hardcoded to extract text from content[0].text, which fails when AWS Bedrock returns responses with reasoning content where the actual text is at content[1].text.

Solution

  • Replace hardcoded data_get($data, 'output.message.content.0.text', '') with flexible $this->extractText($data) method.
  • Add a dedicated test case for reasoning content responses.
  • I also fixed the failing tests and adjusted a few exceptions to keep things consistent.

The handler now correctly processes both standard responses and responses with reasoning content. :)

@ChrisB-TL
Copy link
Collaborator

I'd rather leave ExtractsText separate from the main package, as we have decoupled everything else from the main Anthropic provider.

Bedrock recently announced closer feature parity with the Anthropic API, so will re-review whether that separation is still needed more widely separately.

Will wait until #34 is merged with removal of responseMessages and rebase this then.

pktharindu and others added 6 commits October 3, 2025 13:27
- Fix ConverseTextHandler error message that incorrectly referenced 'Anthropic'
- Standardize exception types to use PrismException instead of generic Exception
- Add consistent provider prefixes to error messages for better debugging
- Ensure all error messages correctly identify their respective handlers

Fixes:
- ConverseTextHandler: 'Anthropic: unknown finish reason' → 'Converse: unknown finish reason'
- AnthropicMessageMap: Use PrismException with 'Anthropic:' prefix for consistency
- ConverseMessageMap: Use PrismException with 'Converse:' prefix for consistency
This commit introduces a new trait `ExtractsText` to handle the extraction of text content from the Converse API response.

The `ConverseTextHandler` is updated to utilize this trait, replacing the previous hardcoded path with a more robust extraction method. This ensures that the text content is correctly parsed, even when nested within reasoning content.

A new test case is added to verify the functionality with reasoning content.
@ChrisB-TL ChrisB-TL force-pushed the fix/open-ai-gpt-oss branch from 08ba230 to 6106fbe Compare October 3, 2025 12:32
@ejunker
Copy link
Contributor

ejunker commented Oct 14, 2025

@ChrisB-TL #34 has been merged so this may be ready. I am also trying to use the OpenAI models in Bedrock like openai.gpt-oss-120b-1:0 and ran into this issue.

@sixlive sixlive merged commit eedc39e into prism-php:main Oct 16, 2025
14 checks passed
@pktharindu pktharindu deleted the fix/open-ai-gpt-oss branch October 17, 2025 02:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support for OpenAI models

4 participants